<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/24 0024
 * Time: 12:13
 */
//三种方式
//simplexml_load_file()
//simplexml_load_string()
//simplexml_import_dom() 兄弟函数 dom_import_simplexml()
$simplexml = simplexml_load_file('./test.xml');
//遍历body里边所有p标签
foreach ($simplexml->body->p as $index => $item) {
//    echo $item;
}
//数字索引表示元素
//echo $simplexml->body->p[0];
//echo $simplexml->body->p[1];
//echo $simplexml->body->p[0]->asXML();
//echo strip_tags($simplexml->body->p[0]->asXML());
//非数字索引表示属性

//echo $simplexml->body['background'];
foreach ($simplexml->body->children() as $child) {
//    echo $child;
}
foreach ($simplexml->body->p[0]->attributes() as $attributes) {
//    echo $attributes;
}
file_put_contents('file.xml',$simplexml->asXML());
